<template>
	<view class="login-container">
		<view class="header">
			<text class="app-name">欢迎登录</text>
		</view>
		
		<view class="form-container">
			<view class="input-group phone-input">
				<text class="country-code">+86</text>
				<input 
					class="input-field" 
					type="number" 
					v-model="loginForm.phone" 
					placeholder="输入手机号"
					maxlength="11"
				/>
			</view>
			
			<view class="input-group password-input">
				<input 
					class="input-field" 
					type="password" 
					v-model="loginForm.password" 
					placeholder="输入密码"
					maxlength="20"
				/>
			</view>
			
			<view class="register-section">
				<text class="register-text">还没有账号，<text class="register-link" @click="goToRegister">立即注册</text></text>
			</view>
			
			<button class="login-btn" @click="handleLogin" :disabled="!canLogin">登录</button>
			
			<view class="social-login">
				<!-- <view class="social-icon wechat" @click="wechatLogin">
					<text class="icon-text">微</text>
				</view>
				<view class="social-icon weibo" @click="weiboLogin">
					<text class="icon-text">微</text>
				</view> -->
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				loginForm: {
					phone: '15100000000',
					password: '123456'
				}
			}
		},
		computed: {
			canLogin() {
				return this.loginForm.phone.trim() && this.loginForm.password.trim()
			}
		},
		methods: {
			handleLogin() {
				if (!this.canLogin) {
					uni.showToast({
						title: '请填写完整信息',
						icon: 'none'
					})
					return
				}
				
				// 显示加载中
				uni.showLoading({
					title: '登录中...'
				})
				
				// 模拟登录请求
				setTimeout(() => {
					uni.hideLoading()
					
					// 简单的模拟验证，支持手机号和用户名登录
				if ((this.loginForm.phone === '15100000000' || this.loginForm.phone === 'admin') && this.loginForm.password === '123456') {
					uni.showToast({
						title: '登录成功',
						icon: 'success'
					})
					
					// 保存登录状态
					uni.setStorageSync('isLogin', true)
					uni.setStorageSync('userInfo', {
						phone: this.loginForm.phone,
						loginTime: new Date().getTime()
					})
					
					// 跳转到首页
					setTimeout(() => {
						uni.reLaunch({
							url: '/pages/index/index'
						})
					}, 1000)
				} else {
					uni.showToast({
						title: '手机号或密码错误',
						icon: 'none'
					})
				}
				}, 1500)
			},
			
			goToRegister() {
				uni.navigateTo({
					url: '/pages/register/register'
				})
			},
			
			wechatLogin() {
				uni.showToast({
					title: '微信登录功能开发中',
					icon: 'none'
				})
			},
			
			weiboLogin() {
				uni.showToast({
					title: '微博登录功能开发中',
					icon: 'none'
				})
			}
		}
	}
</script>

<style scoped>
	.login-container {
		min-height: 100vh;
		background: linear-gradient(135deg, #4A90E2 0%, #7B68EE 100%);
		display: flex;
		flex-direction: column;
		padding: 0;
	}
	
	.header {
		padding: 300rpx 60rpx 80rpx;
		text-align: left;
	}
	
	.app-name {
		font-size: 56rpx;
		color: #ffffff;
		font-weight: bold;
	}
	
	.form-container {
		flex: 1;
		background: #ffffff;
		border-radius: 40rpx 40rpx 0 0;
		padding: 80rpx 60rpx 60rpx;
		position: relative;
	}
	
	.input-group {
		margin-bottom: 40rpx;
		position: relative;
	}
	
	.phone-input {
		display: flex;
		align-items: center;
		border: 2rpx solid #f0f0f0;
		border-radius: 16rpx;
		padding: 0 30rpx;
		height: 100rpx;
		background: #f8f9fa;
	}
	
	.country-code {
		font-size: 32rpx;
		color: #333333;
		margin-right: 20rpx;
		font-weight: 500;
	}
	
	.phone-input .input-field {
		flex: 1;
		border: none;
		background: transparent;
		height: auto;
		padding: 0;
		font-size: 32rpx;
	}
	
	.password-input {
		border: 2rpx solid #f0f0f0;
		border-radius: 16rpx;
		padding: 0 30rpx;
		height: 100rpx;
		background: #f8f9fa;
		display: flex;
		align-items: center;
	}
	
	.password-input .input-field {
		width: 100%;
		border: none;
		background: transparent;
		height: auto;
		padding: 0;
		font-size: 32rpx;
	}
	
	.input-field {
		color: #333333;
		box-sizing: border-box;
	}
	
	.input-field:focus {
		outline: none;
	}
	
	.register-section {
		text-align: center;
		margin-top: 40rpx;
		margin-bottom: 20rpx;
	}
	
	.register-text {
		font-size: 28rpx;
		color: #666666;
	}
	
	.register-link {
		color: #4A90E2;
		text-decoration: underline;
	}
	
	.login-btn {
		width: 100%;
		height: 100rpx;
		background: linear-gradient(135deg, #4A90E2 0%, #7B68EE 100%);
		color: #ffffff;
		border: none;
		border-radius: 50rpx;
		font-size: 36rpx;
		font-weight: bold;
		margin-top: 60rpx;
		margin-bottom: 40rpx;
	}
	
	.login-btn:disabled {
		background: #cccccc;
		color: #999999;
	}
	
	.social-login {
		display: flex;
		justify-content: center;
		gap: 60rpx;
		margin-top: 40rpx;
	}
	
	.social-icon {
		width: 100rpx;
		height: 100rpx;
		border-radius: 50rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		background: #f0f0f0;
	}
	
	.wechat {
		background: #07C160;
	}
	
	.weibo {
		background: #E6162D;
	}
	
	.icon-text {
		font-size: 36rpx;
		color: #ffffff;
		font-weight: bold;
	}
</style>